home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_203 / gurusguide / tasksig.c < prev   
C/C++ Source or Header  |  1992-05-06  |  4KB  |  123 lines

  1. /************************************************************************
  2. **********                                                     **********
  3. **********      T A S K   S I G N A L   I N T E R R U P T      **********
  4. **********      -----------------------------------------      **********
  5. **********                                                     **********
  6. **********        Copyright (C) 1988 Sassenrath Research       **********
  7. **********                All Rights Reserved.                 **********
  8. **********                                                     **********
  9. **********    Example from the "Guru's Guide, Meditation #1"   **********
  10. **********                                                     **********
  11. *************************************************************************
  12. **                                                                     **
  13. **                            - NOTICE -                               **
  14. **                                                                     **
  15. **  The "Guru's Guide, Meditation #1" contains detailed information    **
  16. **  about Amiga interrupts as well as a complete discussion of this    **
  17. **  and other examples.  Meditation #1 and all of its examples were    **
  18. **  written by Carl Sassenrath, the architect of Amiga's multitasking  **
  19. **  operating system.  Copies of the "Guru's Guide" may be obtained    **
  20. **  from:                                                              **
  21. **           GURU'S GUIDE, P.O. BOX 1510, UKIAH, CA 95482              **
  22. **                                                                     **
  23. **  Please include a check for $14.95, plus $1.50 shipping ($4.00 if   **
  24. **  outside North America).  CA residents add 6% sales tax.            **
  25. **                                                                     **
  26. **  This example may be used for any purposes, commercial, personal,   **
  27. **  public, and private, so long as ALL of the above text, copyright,  **
  28. **  mailing address, and this notice are retained in their entirety.   **
  29. **                                                                     **
  30. **  THIS EXAMPLE IS PROVIDED WITHOUT WARRANTY OF ANY KIND.             **
  31. **                                                                     **
  32. ************************************************************************/
  33.  
  34. /*
  35. **  COMPILATION NOTE:
  36. **
  37. **  Compiled under MANX AZTEC C 3.6A.  Use the +L compiler option
  38. **  and the "c32" library.  Link with intrsup.o
  39. */
  40.  
  41.  
  42. #include <exec/exec.h>
  43. #include <hardware/intbits.h>
  44.  
  45. struct Interrupt *Intr = NULL;
  46. long ASignal = -1;
  47.  
  48. /* Structure used by interrupt */
  49. struct SigInfo
  50. {
  51.     long counter;
  52.     long signal;
  53.     struct Task *task;
  54. } IntrData;
  55.  
  56.  
  57. /* Interrupt Processing Code */
  58. VOID    IntrProc();
  59. #asm
  60. EXECBASE    equ    4
  61.         public    _LVOSignal
  62. _IntrProc:
  63.         addq.l    #1,(a1)+    ; counter
  64.         move.l    (a1)+,d0    ; signal
  65.         move.l    (a1)+,a1     ; task
  66.         move.l    EXECBASE,a6
  67.         jsr    _LVOSignal(a6)
  68.         moveq    #0,d0        ; Z-flag - do next server
  69.         rts
  70. #endasm
  71.  
  72.  
  73. main()
  74. {
  75.     int count;
  76.  
  77.     MainInit();
  78.  
  79.     AddIntServer(INTB_VERTB, Intr);
  80.  
  81.     for (count = 0; count < 200; count++)
  82.     {
  83.         Wait(IntrData.signal);
  84.         printf("%d %d\n", count, IntrData.counter);
  85.     }
  86.  
  87.     RemIntServer(INTB_VERTB, Intr);
  88.  
  89.     MainExit();
  90. }
  91.  
  92.  
  93. MainInit()
  94. {
  95.     extern struct Interrupt *MakeIntr();
  96.     extern long AllocSignal();
  97.     extern struct Task *FindTask();
  98.     extern int Enable_Abort;
  99.  
  100.     Enable_Abort = 0;    /* prevent a CTRL-C */
  101.  
  102.     Intr = MakeIntr("signal.example",-60,&IntrProc,&IntrData);
  103.     if (Intr == NULL) MainExit(201);
  104.  
  105.     ASignal = AllocSignal(-1);
  106.     if (ASignal == -1) MainExit(202);
  107.  
  108.     IntrData.counter = 0;
  109.     IntrData.signal = 1 << ASignal;
  110.     IntrData.task = FindTask(NULL);
  111. }
  112.  
  113.  
  114. MainExit(error)
  115.     int error;
  116. {
  117.     FreeIntr(Intr);
  118.  
  119.     if (ASignal != -1) FreeSignal(ASignal);
  120.  
  121.     exit(error);
  122. }
  123.